<template>
  <div>
   <h1>China</h1>
   <h2 ref="title2">北京</h2>
   <h3>西城</h3>
    <button @click="showLog">点击输出h2这个元素</button>
  </div>
</template>

<script lang="ts" setup>
import {ref,defineExpose} from 'vue'
let title2=ref()
function showLog() {
  console.log(title2.value)
}
defineExpose(title2)
</script>
<style scoped>
h1{
  color: red;
}
</style>